/**
 * $Id: Channel.cs 77 2004-09-19 13:31:53Z meebey $
 * $URL: svn://svn.qnetp.net/smartirc/IrcClient/tags/0.2.0/src/Channel.cs $
 * $Rev: 77 $
 * $Author: meebey $
 * $Date: 2004-09-19 15:31:53 +0200 (Sun, 19 Sep 2004) $
 *
 * Copyright (c) 2003-2004 Mirco Bauer <meebey@meebey.net> <http://www.meebey.net>
 * 
 * Full LGPL License: <http://www.gnu.org/licenses/lgpl.txt>
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

using C5;
using System.Collections.Generic;

namespace UrDnd.IrcClient
{
	/// <summary>
	/// 
	/// </summary>
	public class Channel
	{
		private readonly object _lockObject;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="name"> </param>
		public Channel(string name)
		{
		    Mode = "";
		    Topic = "";
		    Bans = new ArrayList<string>();
		    _unsafeUsers = new HashDictionary<string, ChannelUser>();
	    	_lockObject = new object();
		    Name = name;
		    Key = string.Empty;
		}

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public string Name { get; private set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public string Key { get; set; }

	    /// <summary>
		/// 
		/// </summary>
		/// <value> </value>
		public HashDictionary<string, ChannelUser> Users
		{
			get
			{
				return (HashDictionary<string, ChannelUser>) UnsafeUsers.Clone();
			}
		}

		private readonly HashDictionary<string, ChannelUser> _unsafeUsers;

		/// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    internal HashDictionary<string, ChannelUser> UnsafeUsers
		{
			get
			{
				lock (_lockObject)
					return _unsafeUsers;
			}
		}

	    /// <summary>
		/// 
		/// </summary>
		/// <value> </value>
		public IEnumerable<ChannelUser> Ops
		{
			get
			{
				foreach (var pair in UnsafeUsers.Filter(x => x.Value.IsOp))
					yield return pair.Value;
			}
		}

	    /// <summary>
		/// 
		/// </summary>
		/// <value> </value>
		public IEnumerable<ChannelUser> Voices
		{
			get
			{
				foreach (var pair in UnsafeUsers.Filter(x => x.Value.IsOp))
					yield return pair.Value;
			}
		}

		/// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public System.Collections.Generic.IList<string> Bans { get; private set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public string Topic { get; set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public int UserLimit { get; set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public string Mode { get; set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public int SynctimeStart { get; set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public int SynctimeStop { get; set; }

	    /// <summary>
	    /// 
	    /// </summary>
	    /// <value> </value>
	    public int Synctime { get; set; }
	}
}
